//
//  QZShowScrollCell.m
//  WWShop
//
//  Created by 超群 on 15/10/14.
//  Copyright © 2015年 qunzhu.Team. All rights reserved.
//

#import "QZShowScrollCell.h"
#import "QZHairDetailViewController.h"

@interface QZShowScrollCell()<UIScrollViewDelegate>


@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) UIPageControl *page;

@end

@implementation QZShowScrollCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
        self.contentView.backgroundColor =[UIColor colorWithRed:(240)/255.0f green:240/255.0f blue:(240)/255.0f alpha:1];
        
        [self createScrollView];
        [self cretePage];
    }
    return self;
    
    
}

-(void)cretePage{
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_W-100)/2.0, CGRectGetMaxY(_scrollView.frame)+2, 100,10)];

    [self.contentView addSubview:view];
    
    _page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 0, 100, 10)];
    
    [view addSubview:_page];
    
    _page.numberOfPages = 5;
    
    
    _page.currentPageIndicatorTintColor = [UIColor colorWithRed:180/255.0 green:90/255.0 blue:234/255.0 alpha:1];
    

    _page.pageIndicatorTintColor = [UIColor grayColor];
    
    
}

-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    
    

    
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    int index = scrollView.contentOffset.x/scrollView.frame.size.width;
    
    
    _page.currentPage = index;
    
}
- (void)createScrollView{
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 260)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:bgView];
    
    
    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, 5, 10)];
    view.backgroundColor = [UIColor colorWithRed:180/255.0 green:90/255.0 blue:234/255.0 alpha:1];;
    [bgView addSubview:view];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(view.frame)+10, 6, 100, 30)];
    label.textColor = [UIColor colorWithRed:180/255.0 green:90/255.0 blue:234/255.0 alpha:1];
    label.text = @"热门活动";
    [bgView addSubview:label];
    

    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 33, SCREEN_W-20, 215)];
//    _scrollView.backgroundColor = [UIColor brownColor];
    _scrollView.delegate = self;
    _scrollView.pagingEnabled = YES;
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.showsVerticalScrollIndicator = NO;
    [bgView addSubview:_scrollView];
    
    for (int i = 0; i<5; i++) {
        
        UIImageView *view = [[UIImageView alloc]initWithFrame:CGRectMake(i*_scrollView.frame.size.width, 0, _scrollView.frame.size.width, _scrollView.frame.size.height)];
        view.userInteractionEnabled = YES;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imageClick:)];
        [view addGestureRecognizer:tap];
        view.image = [UIImage imageNamed:@"shop1"];
        
        [_scrollView addSubview:view];
    }
    _scrollView.contentSize = CGSizeMake(5*_scrollView.frame.size.width, 0);
}

-(void)imageClick:(UITapGestureRecognizer *)tap{
    
    if (_block) {
        _block(nil);
    }

}


-(void)setImages:(NSArray *)images{
    _images = images;
    
    for (int i = 0; i< _scrollView.subviews.count; i++) {
        UIImageView *imageView = (UIImageView *)_scrollView.subviews[i];
        
#warning 添 加 图 片------------------------------------------------------
        
        
    }
    
    
    
    
}

@end
